package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.aop_whh.annotation.OperateLog;
import com.cskaoyan.wordmemorize.common.constant.ResultCodeEnum;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.LevelDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.LevelCommand;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.service.LevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/level")
public class LevelController_whh {

    @Autowired
    LevelService levelService;


    //查看列表并搜索
    @GetMapping("list")
    public Result getList(Integer pageNum, Integer count, String levelName) {
        PageRequest pageRequest = new PageRequest();
        pageRequest.setPageNum(pageNum);
        pageRequest.setCount(count);
        pageRequest.setKeyword(levelName);
        PageDTO<LevelDTO> levelList = levelService.getLevelList(pageRequest);
        return Result.ok(levelList);
    }

    //添加等级
    @OperateLog(dateType = "等级", operateType = 1)
    @PostMapping
    public Result postLevel(@RequestBody LevelCommand levelCommand) {
        levelService.addLevel(levelCommand);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }

    //修改等级
    @OperateLog(dateType = "等级", operateType = 4)
    @PutMapping
    public Result putLevel(@RequestBody LevelCommand levelCommand) {
        levelService.updateLevel(levelCommand);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }

    @OperateLog(dateType = "等级", operateType = 2)
    @DeleteMapping("{id}")
    public Result deleteLevel(@PathVariable Long id) {
        levelService.deleteLevel(id);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }

    @OperateLog(dateType = "等级", operateType = 3)
    @DeleteMapping("batch")
    public Result deleteLevelBatch(@RequestBody BatchDeleteCommand command) {
        levelService.deleteLevels(command);
        return Result.ok(ResultCodeEnum.SUCCESS);
    }
}
